import { create } from 'zustand';
import { Product, ProductProcess } from '../types';

interface ProductState {
  products: Product[];
  currentProduct: Product | null;
  processes: ProductProcess[];
  loading: boolean;
  error: string | null;
  
  // Actions
  setProducts: (products: Product[]) => void;
  setCurrentProduct: (product: Product | null) => void;
  setProcesses: (processes: ProductProcess[]) => void;
  setLoading: (loading: boolean) => void;
  setError: (error: string | null) => void;
  clearError: () => void;
}

export const useProductStore = create<ProductState>((set) => ({
  products: [],
  currentProduct: null,
  processes: [],
  loading: false,
  error: null,
  
  setProducts: (products) => set({ products }),
  setCurrentProduct: (product) => set({ currentProduct: product }),
  setProcesses: (processes) => set({ processes }),
  setLoading: (loading) => set({ loading }),
  setError: (error) => set({ error }),
  clearError: () => set({ error: null }),
}));